<?php

namespace app\common\model;

use think\Model;

class User extends Model
{
    /**
     * 根据用户名获取用户的基本信息
     * @param $username
     * @return array|Model|null
     * @author bjy
     */
    public function getInfoByUsername($username)
    {
        $where  = [
            "username" => trim($username),
        ];
        $result = $this->where($where)->find();
        return $result;
    }

    /**
     * 根据手机号获取用户的基本信息
     * @param string $phone 用户手机号
     * @return array|Model|null
     * @author bjy
     */
    public function getInfoByPhone($phone)
    {
        $where  = [
            "phone_number" => trim($phone),
        ];
        $result = $this->where($where)->find();
        return $result;
    }

    /**
     * 根据id获取用户的基本信息
     * @param string $id 用户id
     * @return array|Model|null
     * @author bjy
     */
    public function getInfoById($id)
    {
        $where  = [
            "id" => intval($id),
        ];
        $result = $this->where($where)->find();
        return $result;
    }

    /**
     * 根据id修改数据
     * @param int $id 数据id
     * @param array $data 修改的数据
     * @return bool
     * @author bjy
     */
    public function updateById($id, $data)
    {
        $where  = [
            "id" => intval($id),
        ];
        $result = $this->where($where)->save($data);
        return $result;
    }
}